package pers.zh.parking.mvp.ui.adapter;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import pers.zh.parking.R;
import pers.zh.parking.data.entity.Evaluation;
import pers.zh.parking.data.entity.ParkRecord;
import pers.zh.parking.data.entity.ParkingLot;
import pers.zh.parking.data.enums.RecordStatus;
import pers.zh.parking.utils.MyUtils;
import pers.zjc.commonlibs.util.StringUtils;
import pers.zjc.commonlibs.util.TimeUtils;

public class LotManageAdapter extends BaseQuickAdapter<ParkingLot, BaseViewHolder> {

    public LotManageAdapter(@Nullable List<ParkingLot> data) {
        super(R.layout.rv_item_lot_manage, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, ParkingLot lot) {
        helper.setText(R.id.tvLotName, lot.getName());
        genLotInfo(helper, lot);
    }

    private void genLotInfo(BaseViewHolder helper, ParkingLot lot) {
        LinearLayout llRsvInfo = helper.itemView.findViewById(R.id.llRsvInfo);
        // 解决recyclerView复用导致多次调用addView,重复的问题
        llRsvInfo.removeAllViews();
        Map<String, String> map = new LinkedHashMap<>();
        map.put("经度", String.valueOf(lot.getLatitude()));
        map.put("纬度", String.valueOf(lot.getLongitude()));
        map.put("位置", lot.getLocation());
        map.put("计费标准", lot.getPriceStr());
        map.put("空闲车位", String.valueOf(lot.getSpaceFree()));
        map.put("总车位", String.valueOf(lot.getSpaceTotal()));
        map.put("支付方式", lot.getPayWayStr());
        for (Map.Entry<String, String> entry : map.entrySet()) {
            View view = LayoutInflater.from(mContext)
                                      .inflate(R.layout.item_hor_key_value,
                                              (ViewGroup)helper.itemView.getParent(), false);
            TextView tvKey = view.findViewById(R.id.tvKey);
            TextView tvValue = view.findViewById(R.id.tvValue);
            tvKey.setText(entry.getKey());
            tvValue.setText(entry.getValue());
            llRsvInfo.addView(view);
        }
    }
}
